﻿<UserControl x:Class="Berico.SnagL.UI.IconNode"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL4"  
             xmlns:converters="clr-namespace:Berico.Common.UI.Converters;assembly=Berico.Common"             
             xmlns:behaviors="clr-namespace:Berico.Common.UI.Behaviors;assembly=Berico.Common"   
             xmlns:triggers="clr-namespace:Berico.Common.UI.Triggers;assembly=Berico.Common"             
             xmlns:ui="clr-namespace:Berico.SnagL.UI"  
             ui:VisualStates.CurrentState="{Binding CurrentState}"
             mc:Ignorable="d"
             Height="{Binding Height, Mode=TwoWay}"
             Width="{Binding Width, Mode=TwoWay}"
             >

    <UserControl.RenderTransform>
        <ScaleTransform CenterX="{Binding ScaleCenter.X}" CenterY="{Binding ScaleCenter.Y}" ScaleX="{Binding Scale, FallbackValue=1}" ScaleY="{Binding Scale, FallbackValue=1}" />
    </UserControl.RenderTransform>
    
    <UserControl.Resources>
        <converters:VisibilityConverter x:Key="VisibilityConverter" />
    </UserControl.Resources>
    
    <!-- Attach behaviors -->
    <i:Interaction.Behaviors>
        <behaviors:SizeChangedHandlerBehavior Command="{Binding SizeChangedCommand}" PassEventArgsToCommand="true" />        
        <behaviors:DoubleClickBehvaior DoubleClickSpeed="200" Command="{Binding MouseDoubleClickCommand}" PassEventArgsToCommand="True" />
    </i:Interaction.Behaviors>

    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <triggers:AdvancedEventToCommand Command="{Binding NodeLoadedCommand}" PassEventDetailsToCommand="True" />            
        </i:EventTrigger>
        <!-- Wire the MouseLeftButtonDown event to the corresponding command in the ViewModel -->
        <i:EventTrigger EventName="MouseLeftButtonDown">
            <cmd:EventToCommand Command="{Binding MouseLeftButtonDown}" PassEventArgsToCommand="True"/>
        </i:EventTrigger>
        <!-- Wire the MouseLeftButtonUp event to the corresponding command in the ViewModel -->
        <i:EventTrigger EventName="MouseLeftButtonUp">
            <cmd:EventToCommand Command="{Binding MouseLeftButtonUp}" PassEventArgsToCommand="True"/>
        </i:EventTrigger>
        <!-- Wire the MouseRightButtonDown event to the corresponding command in the ViewModel -->
        <i:EventTrigger EventName="MouseRightButtonDown">
            <cmd:EventToCommand Command="{Binding MouseRightButtonDown}" PassEventArgsToCommand="True"/>
        </i:EventTrigger>
        <!-- Wire the MouseRightButtonUp event to the corresponding command in the ViewModel -->
        <i:EventTrigger EventName="MouseRightButtonUp">
            <cmd:EventToCommand Command="{Binding MouseRightButtonUp}" PassEventArgsToCommand="True"/>
        </i:EventTrigger>
        <i:EventTrigger EventName="MouseEnter">
            <cmd:EventToCommand Command="{Binding MouseEnterCommand}" PassEventArgsToCommand="True"/>
        </i:EventTrigger>
        <i:EventTrigger EventName="MouseLeave">
            <cmd:EventToCommand Command="{Binding MouseLeaveCommand}" PassEventArgsToCommand="True"/>
        </i:EventTrigger>        
        <!-- Wire the MouseWheel event to the corresponding command in the ViewModel -->
        <!--<i:EventTrigger EventName="MouseWheel">
            <cmd:EventToCommand Command="{Binding MouseWheel}" PassEventArgsToCommand="True"/>
        </i:EventTrigger>-->
        <i:EventTrigger EventName="MouseMove">
            <cmd:EventToCommand Command="{Binding MouseMoveCommand}" PassEventArgsToCommand="True" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    
    <Grid x:Name="LayoutRoot" Visibility="{Binding IsHidden, Converter={StaticResource VisibilityConverter}, ConverterParameter='true'}">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Normal" />
            </VisualStateGroup>
            <VisualStateGroup x:Name="SelectionStates">
                <VisualState x:Name="Unselected" />
                <VisualState x:Name="Selected">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="SelectionHighlight">
                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                       <!-- <ColorAnimation Duration="00:00:00" To="{Binding SelectionColor.Color}" Storyboard.TargetName="BackgroundTop"  Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" />
                        <ColorAnimation Duration="00:00:00" To="{Binding SelectionColor.Color}" Storyboard.TargetName="BackgroundBottomLeft"  Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" />
                        <ColorAnimation Duration="00:00:00" To="{Binding SelectionColor.Color}" Storyboard.TargetName="BackgroundBottomRight"  Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" />-->
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        
        <!-- Background Highlight -->
        <Ellipse Grid.Row="0" Grid.RowSpan="2" Height="75" Width="75" Visibility="{Binding BackgroundVisibility}">
            <Ellipse.Fill>
                <RadialGradientBrush GradientOrigin="0.5, 0.5" Center="0.5,0.5" RadiusX="0.5" RadiusY="0.5">
                    <GradientStop Color="{Binding BackgroundColor.Color, FallbackValue=Red}" Offset="0.55" />
                    <GradientStop Color="Transparent" Offset="1" />
                </RadialGradientBrush>
            </Ellipse.Fill>
        </Ellipse>

        <!-- Represents some label for the node -->
        <Rectangle Grid.Row="1" Fill="White" Opacity=".5" />
        <TextBlock Grid.Row="1" MaxWidth="150" MinWidth="70" Text="{Binding DisplayValue,FallbackValue=test}" TextAlignment="Center" TextWrapping="Wrap"  />
        
        <!-- Selection Indication -->
        <Border Grid.Row="0" x:Name="SelectionHighlight" MaxWidth="70" MaxHeight="70"  Visibility="Collapsed" BorderBrush="{Binding SelectionColor,FallbackValue=#FF4A75A9}" BorderThickness="4" />

        <!-- Represents some image for the node -->
        <Image Grid.Row="0" Height="45" Width="45" Margin="10" Source="{Binding ImageSource,FallbackValue=/Berico.SnagL;component/Resources/Icons/person.png}" />
    </Grid>

</UserControl>
